#ifndef _UTILEX_FILE_HPP_
#define _UTILEX_FILE_HPP_

#include <crt_util.h>

#ifdef __cplusplus

static_inline path_string GetExePathString()
{
    basic_tchar szPath[MAX_PATH + 1] = {0x00};
    get_executepath(pid_null, szPath, MAX_PATH);
    path_string strPath(szPath);
    return strPath;
}

static_inline BYTE* ReadFileMem(const path_string& path, unsigned long& len)
{
    _fd_t hFile = INVALID_HANDLE_VALUE;
    size_t read = 0;
    BYTE* data = NULL;
    hFile = _file_open(path.c_str(), O_RDWR, 0644);
    rc_error(hFile != INVALID_HANDLE_VALUE, NULL);

    size_t ulFileLen = _file_fsize(hFile) & UINT32_MAX;
    if (ulFileLen == 0)
        goto end;

    read = ulFileLen & UINT32_MAX;

    data = ALLOC_NEW BYTE[ulFileLen + 1]();

    if (data == NULL)
        goto end;

    len = _file_read(hFile, data, read);
end:
    _file_close(hFile);
    return data;
}

#endif

#endif
